<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.21/dist/css/layui.css" rel="stylesheet">
</head>
<body>
<div class="layui-tab" lay-filter="test-hash">
    <ul class="layui-tab-title">
        <li class="layui-this" lay-id="11">标签1</li>
        <li lay-id="22">标签2</li>
        <li lay-id="33">标签3</li>
        <li lay-id="44">标签4</li>
        <li lay-id="55">标签5</li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">内容-1</div>
        <div class="layui-tab-item">内容-2</div>
        <div class="layui-tab-item">内容-3</div>
        <div class="layui-tab-item">内容-4</div>
        <div class="layui-tab-item">内容-5</div>
    </div>
</div>

<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script src="//unpkg.com/layui@2.9.21/dist/layui.js"></script>
<script>
    layui.use(function(){
        var element = layui.element;

        // hash 地址定位
        var hashName = 'tabid'; // hash 名称
        var layid = location.hash.replace(new RegExp('^#'+ hashName + '='), ''); // 获取 lay-id 值

        // 初始切换
        element.tabChange('test-hash', layid);
        // 切换事件
        element.on('tab(test-hash)', function(obj){
            location.hash = hashName +'='+ this.getAttribute('lay-id');
        });
    });
</script>

</body>
</html>